/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package embeddedpaint.user_interface;

import embeddedpaint.model.feature.AImageTool;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Observable;
import java.util.Observer;
import javax.swing.AbstractButton;


public class MyButton extends Observable implements Observer
{
    private static final boolean M_IS_BORDER_PAINTED = false;
    
    private AbstractButton       m_button;
    private AImageTool           m_tool;
    
    public MyButton (AbstractButton m_button, AImageTool m_tool)
    {
        this.m_button = m_button;
        this.m_tool   = m_tool;
        
        this.init();
        
        this.m_tool.addObserver(this);
    }
    
    private void init ()
    {
        this.m_button.setToolTipText   (this.m_tool.getLabel());
        this.m_button.setEnabled       (this.m_tool.isM_enable());
        this.m_button.addActionListener(this.m_tool);
        this.m_button.setBorderPainted (M_IS_BORDER_PAINTED);
        
        this.m_button.addActionListener(new ActionListener()
        {
            @Override
            public void actionPerformed(ActionEvent e)
            {
                notifyToolBar();
            }
        });
    }
    
    public void notifyToolBar ()
    {
        this.setChanged();
        this.notifyObservers();
    }
    
    @Override
    public void update (Observable o, Object arg)
    {
        this.m_button.setEnabled (this.m_tool.isM_enable());
        this.m_button.setSelected(this.m_tool.isActif());
    }
    
    void disable ()
    {
        this.m_button.setSelected(false);
       
        this.m_tool.dispose();
    }
    
    public AbstractButton getM_button ()
    {
        return m_button;
    }
}
